/*
 *  $Id: Necromancy.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Spells {
    public class Necromancy: SpellCard<GraveyardData> {
        public Necromancy(): base("001_d_s_necromancy") {
            Level = CompleteLevel.ReadyForTest;
            Version = 1;
            Element = ElementType.Darkness;
            Value = 100;
            Target = new GraveyardTarget(GetTargetPhrase(), true, true, IsPossibleCost);
            AddManaCost(ElementType.Darkness, 4);
            AddCondition(new CreaturesCondition(true, 1));
        }

        private static bool IsPossibleCost(TargetRequest request, GraveyardItem item) {
            return item.CanResurrect && item.Card.GetSumMana() < 4;
        }

        private static readonly Languages.CardPhrase<Necromancy> Action = new Languages.CardPhrase<Necromancy>("action");

        protected override void DoAction(TargetArgs<GraveyardData> args) {
            int place = args.Player.GetRandomFreePlace();
            if (place < 0) return;
            args.Player.Game.Log.Add(Action.Phrase, args.Player, args.Target.Item.Card);
            Creature cr = args.Target.Owner.ResurrectCreatureToPlayer(args.Player, args.Target.Item, place, false);
            if (!cr.HasFlag<Affects.Undead>()) cr.AddAffect<Affects.Undead>();
        }
    }
}
